package org.nix.entity;

import org.nix.entity.base.BaseEntity;

import javax.persistence.*;

/**
 * Create by zhangpe0312@qq.com on 2018/4/19.
 *
 * 城市与城市之间的距离
 *
 * 实体城市包含了这个辅助表，该表表示拥有这个实体的城市能够到达其他城市的距离
 */
@Table(name = "CityDistance")
@Entity
public class CityDistance extends BaseEntity{

    private City fromCity;

    //到这个城市
    private City toCity;

    // from -> to 的距离,默认为不可达
    private double distance = 100000;

    public CityDistance() {
    }

    public CityDistance(City fromCity, City toCity, double distance) {
        this.fromCity = fromCity;
        this.toCity = toCity;
        this.distance = distance;
    }

    @ManyToOne(targetEntity = City.class , fetch = FetchType.LAZY , cascade = CascadeType.ALL)
    @JoinColumn(name = "toCity")
    public City getToCity() {
        return toCity;
    }

    @Column(name = "distance")
    public double getDistance() {
        return distance;
    }

    @ManyToOne(targetEntity = City.class , fetch = FetchType.EAGER , cascade = CascadeType.ALL)
    @JoinColumn(name = "fromCity")
    public City getFromCity() {
        return fromCity;
    }

    public void setToCity(City toCity) {
        this.toCity = toCity;
    }

    public void setDistance(double distance) {
        this.distance = distance;
    }

    public void setFromCity(City fromCity) {
        this.fromCity = fromCity;
    }
}
